package com.meitianhui.convenitenbuy.module.home.adapter;


import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.os.Build;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.util.TypedValue;
import android.view.View;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseMultiItemQuickAdapter;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.google.gson.reflect.TypeToken;
import com.meitianhui.convenitenbuy.Constants;
import com.meitianhui.convenitenbuy.R;
import com.meitianhui.convenitenbuy.config.InfoProvider;
import com.meitianhui.convenitenbuy.module.home.model.bean.BannerBean;
import com.meitianhui.convenitenbuy.module.home.model.bean.HomeMultiItemType;
import com.meitianhui.convenitenbuy.module.home.model.bean.RecommendGoods;
import com.meitianhui.convenitenbuy.module.home.ui.HomeFragment;
import com.meitianhui.convenitenbuy.module.home.ui.activity.web.AdWebViewActivity;
import com.meitianhui.convenitenbuy.util.EmptyUtil;
import com.meitianhui.convenitenbuy.util.GlideUtils;
import com.meitianhui.convenitenbuy.util.GsonParserUtils;
import com.meitianhui.convenitenbuy.util.SystemUtils;
import com.meitianhui.convenitenbuy.widget.NoScrollWebView;
import com.youth.banner.Banner;
import com.youth.banner.listener.OnBannerListener;
import com.youth.banner.loader.ImageLoader;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import static com.meitianhui.convenitenbuy.Constants.BANNER_TIME;

public class HomeAdapter extends BaseMultiItemQuickAdapter<HomeMultiItemType, BaseViewHolder> {

    private Context context;
    private int mType;
    private int mTypeChooseBg = R.mipmap.icon_home_edinburgh;
    private String mTypeColor = "#c7693b";
    private String mTypeChooseColor = "#ea5d08";
    private List<RecommendGoods.Stores.PicInfo> picInfo = null;
    private HomeEdinburghGoodsAdapter eAdapter = null;
    private HomeFightGroupAdapter fAdapter = null;
    private HomeBrandAdapter bAdapter = null;
    /*
     * 0 : 代表不没有更多了
     * 1 : 代表可以加载更改
     * 2 : 代表没有数据
     * 3 : 代表不没有更多了下面留白
     * 5 : 加载中 下面留白
     * 6 : 没找到网络
     */
    private int mLoadMoreType = 1;


    public HomeAdapter(Context context, List<HomeMultiItemType> data, int type) {
        super(data);
        this.context = context;
        this.mType = type;
        addItemType(HomeMultiItemType.ITEM_BANNER, R.layout.item_home_banner);
        addItemType(HomeMultiItemType.ITEM_MEMBER_FUNCTION, R.layout.item_home_member_function);
        addItemType(HomeMultiItemType.ITEM_RECOMMEND_GOODS, R.layout.item_home_recommend_goods);
        addItemType(HomeMultiItemType.ITEM_ZERO_BUY, R.layout.item_home_zero_buy);
        addItemType(HomeMultiItemType.ITEM_GOOD_TYPE, R.layout.item_home_good_type);
        addItemType(HomeMultiItemType.ITEM_GOOD_INFO, R.layout.item_home_good_info);
        addItemType(HomeMultiItemType.ITEM_PULL_DATA, R.layout.item_home_pulltorefresh_more);
    }

    @Override
    public int getItemCount() {
        // 类型数量
        return 7;
    }

    @Override
    protected void convert(BaseViewHolder helper, HomeMultiItemType item) {
        switch (helper.getItemViewType()) {
            case HomeMultiItemType.ITEM_BANNER:   //banner布局
                Banner banner = helper.getView(R.id.banner);
                RelativeLayout bannerSearch = helper.getView(R.id.banner_search);
                //设置透明状态栏后，
                int systemBarHeight = SystemUtils.getSystemBarHeight(context);
                bannerSearch.setPadding(
                        bannerSearch.getPaddingLeft(),
                        systemBarHeight,
                        bannerSearch.getPaddingRight(),
                        bannerSearch.getPaddingBottom());
                bannerSearch.getLayoutParams().height = systemBarHeight
                        + (int) TypedValue.applyDimension(
                                TypedValue.COMPLEX_UNIT_DIP, 59,
                                context.getResources().getDisplayMetrics());

                TextView tvLocation = helper.getView(R.id.tv_location);
                tvLocation.setText(InfoProvider.getCity(context));
                //搜索页面
                helper.setOnClickListener(R.id.ll_search, new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        if (homeAdapterOnClickListener != null) {
                            homeAdapterOnClickListener.searchClick();
                        }
                    }
                });
                //扫描二维码
                helper.setOnClickListener(R.id.iv_scan, new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        if (homeAdapterOnClickListener != null) {
                            homeAdapterOnClickListener.scanCodeClick();
                        }
                    }
                });
                if (item.bannerBean == null) {
                    return;
                }
                List<BannerBean.ListBean> list = item.bannerBean.getList();
                HashMap<String, String> map = item.bannerBean.getDoc_url();
                List<String> images = new ArrayList<>();
                if (list != null) {
                    for (int i = 0; i < list.size(); i++) {
                        String imgUrl = map.get(list.get(i).getPath_id());

                        images.add(imgUrl);
                    }
                }
                banner.setImages(images)
                        .setDelayTime(BANNER_TIME)   //设置轮播时间
                        .setImageLoader(new GlideImageLoader())
                        .start();
                banner.setOnBannerListener(new OnBannerListener() {
                    @Override
                    public void OnBannerClick(int position) {
                        if (list != null) {
                            String url = "";
                            String topUrl = list.get(position).getUrl();
                            String imgUrl = map.get(list.get(position).getPath_id());
                            if (!TextUtils.isEmpty(topUrl)) {
                                url = topUrl + "&banner=" + imgUrl;
                            }
                            if (!TextUtils.isEmpty(url)) {
                                Intent intent = new Intent(mContext, AdWebViewActivity.class);
                                intent.putExtra("url", url);
                                mContext.startActivity(intent);
                            }
                        }
                    }
                });
                break;
            case HomeMultiItemType.ITEM_MEMBER_FUNCTION:   //会员权益功能
                helper.setOnClickListener(R.id.tv_sign_in, v -> {    //签到
                    if (homeAdapterOnClickListener != null) {
                        homeAdapterOnClickListener.signInClick();
                    }
                });
                helper.setOnClickListener(R.id.tv_phone_charge, v -> {
                    if (homeAdapterOnClickListener != null) {
                        homeAdapterOnClickListener.phoneChargeClick();
                    }
                });
                helper.setOnClickListener(R.id.tv_new_strategy, v -> {
                    if (homeAdapterOnClickListener != null) {
                        homeAdapterOnClickListener.newStrategyClick();
                    }
                });
                helper.setOnClickListener(R.id.tv_member_rules, v -> {
                    if (homeAdapterOnClickListener != null) {
                        homeAdapterOnClickListener.memberRulesClick();
                    }
                });
                helper.setOnClickListener(R.id.tv_business_coo, v -> {
                    if (homeAdapterOnClickListener != null) {
                        homeAdapterOnClickListener.businessCooClick();
                    }
                });
                break;
            case HomeMultiItemType.ITEM_RECOMMEND_GOODS:  //推荐商品  包含限时领取和明日预告
                ImageView ivLimits = helper.getView(R.id.iv_limits);   //限时秒杀
                ImageView ivTomorrow = helper.getView(R.id.iv_tommorrow);  //明日预告
                LinearLayout llRecommendGood = helper.getView(R.id.ll_recommend_goods);
                RecyclerView rvRecommendGoods = helper.getView(R.id.item_rv_recommend_goods);   //商品列表
                //设置布局管理器
                LinearLayoutManager linearLayoutManager = new LinearLayoutManager(mContext);
                linearLayoutManager.setOrientation(LinearLayoutManager.HORIZONTAL);
                rvRecommendGoods.setLayoutManager(linearLayoutManager);
                if (item.recommendGoods == null) {
                    return;
                }
                List<RecommendGoods.Stores> stores = item.recommendGoods.getList();
                try {
                    if (item.recommendGoods.getList() == null) {
                        return;
                    }
                    //商品大小必须大于等于2，因为限时秒杀跟明日特惠必须有
                    if (item.recommendGoods.getList().size() >= 2) {
                        //必须大于等于2，说明有限时秒杀跟明日特惠
                        List<RecommendGoods.Stores.PicInfo> picInfo2;
                        //设置限时秒杀
                        TypeToken<List<RecommendGoods.Stores.PicInfo>> typeToken = new TypeToken<List<RecommendGoods.Stores.PicInfo>>() {
                        };
                        picInfo = GsonParserUtils.getInstance().fromJson(stores.get(0).getPic_info(), typeToken);
                        if (picInfo != null) {
                            GlideUtils.setRectImage(mContext, item.recommendGoods.getDoc_url().get(picInfo.get(0).getPath_id()), R.mipmap.icon_default_picture_store, R.mipmap.icon_default_picture_store, ivLimits);
                        }
                        ivLimits.setOnClickListener(new View.OnClickListener() {
                            @Override
                            public void onClick(View v) {
                                if (homeAdapterOnClickListener != null) {
                                    homeAdapterOnClickListener.limitTimeClick(item.recommendGoods.getList().get(0).getGoods_id(), item.recommendGoods.getDoc_url().get(picInfo.get(0).getPath_id()));
                                }
                            }
                        });
                        //设置明日预告
                        picInfo2 = GsonParserUtils.getInstance().fromJson(stores.get(1).getPic_info(), typeToken);
                        if (picInfo2 != null) {
                            GlideUtils.setRectImage(mContext, item.recommendGoods.getDoc_url().get(picInfo2.get(0).getPath_id()), R.mipmap.icon_default_picture_store, R.mipmap.icon_default_picture_store, ivTomorrow);
                        }
                        ivTomorrow.setOnClickListener(new View.OnClickListener() {
                            @Override
                            public void onClick(View v) {
                                if (homeAdapterOnClickListener != null) {
                                    homeAdapterOnClickListener.tomorrowClick(item.recommendGoods.getList().get(1).getGoods_id());
                                }
                            }
                        });
                        //设置领了么商品列表数据
                        List<RecommendGoods.Stores> tempList = new ArrayList<>();
                        //领了么商品列表数据取2开始，0，代表限时、1代表明日
                        if (stores.size() > 2) {
                            for (int i = 0; i < stores.size(); i++) {
                                if (i == 0 || i == 1) {
                                    continue;
                                }
                                tempList.add(stores.get(i));
                            }
                            //拿到领了么商品列表的数据，如果大于0，则显示view
                            if (tempList.size() > 0) {
                                HomeItemReGoodsAdapter adapter = new HomeItemReGoodsAdapter(context, tempList, item.recommendGoods.getDoc_url());
                                rvRecommendGoods.setAdapter(adapter);
                                adapter.setOnItemClickListener(new OnItemClickListener() {
                                    @Override
                                    public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
                                        if (homeAdapterOnClickListener != null) {
                                            HashMap<String, String> doc_url_all = item.recommendGoods.getDoc_url();
                                          /*  String pic_info = tempList.get(position).getPic_info();
                                            String temp_url = doc_url_all.get(tempList.get(position).getPic_info());*/
                                            TypeToken<List<RecommendGoods.Stores.PicInfo>> typeToken = new TypeToken<List<RecommendGoods.Stores.PicInfo>>() {
                                            };
                                            try {
                                                List<RecommendGoods.Stores.PicInfo> picInfo = GsonParserUtils.getInstance().fromJson(tempList.get(position).getPic_info(), typeToken);
                                                String temp_url = doc_url_all.get(picInfo.get(0).getPath_id());
                                                homeAdapterOnClickListener.edinburghClick(tempList.get(position).getGoods_id(), tempList.get(position).getData_source(), temp_url);
                                            } catch (Exception e) {
                                                e.printStackTrace();
                                            }
                                        }
                                    }
                                });
                            }
                            llRecommendGood.setVisibility(View.VISIBLE);
                        } else {
                            llRecommendGood.setVisibility(View.GONE);
                        }
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }
                break;

            case HomeMultiItemType.ITEM_ZERO_BUY:
                ImageView ivZeroBuy = helper.getView(R.id.iv_home_zero_buy);
                if (item.zeroBuyImage == null || EmptyUtil.isEmpty(item.zeroBuyImage.getDoc_url())) {
                    ivZeroBuy.setVisibility(View.GONE);
                    return;
                }

                ivZeroBuy.setVisibility(View.VISIBLE);
                Map<String, String> imgUrls = item.zeroBuyImage.getDoc_url();
                String imageUrl = "";
                for (Map.Entry<String, String> entry : imgUrls.entrySet()) {
                    imageUrl = entry.getValue();
                }

                GlideUtils.setRectImage(mContext, imageUrl, R.mipmap.icon_default_picture,
                        R.mipmap.icon_default_picture, ivZeroBuy);
                ivZeroBuy.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        if (homeAdapterOnClickListener != null) {
                            homeAdapterOnClickListener.zeroBuyClick();
                        }
                    }
                });
                break;

            case HomeMultiItemType.ITEM_GOOD_TYPE:    //商品类型

                LinearLayout mlLSmallTypeBg = helper.getView(R.id.ll_small_type_bg);
                //大的类目
                int mTvTypeIds[] = {R.id.tv_type_edinburgh, R.id.tv_type_will, R.id.tv_type_fight_group, R.id.tv_type_brand};
                TextView mTvType[] = new TextView[4];
                int mIvTypeIds[] = {R.id.iv_type_edinburgh, R.id.iv_type_will, R.id.iv_type_fight_group, R.id.iv_type_brand};
                ImageView mIvType[] = new ImageView[4];
                //小的类目
                int mTvTypeSmallIds[] = {R.id.tv_type_small_daily_home, R.id.tv_type_small_electrical, R.id.tv_type_small_baby_product, R.id.tv_type_small_clothes, R.id.tv_type_small_fresh_food};
                TextView mTvTypeSmall[] = new TextView[5];
                int mIvTypeSmallIds[] = {R.id.iv_type_small_daily_home, R.id.iv_type_small_electrical, R.id.iv_type_small_baby_product, R.id.iv_type_small_clothes, R.id.iv_type_small_fresh_food};
                ImageView mIvTypeSmall[] = new ImageView[5];
                //绑定事件
                //大类
                for (int i = 0; i < mTvTypeIds.length; i++) {
                    mTvType[i] = helper.getView(mTvTypeIds[i]);
                }
                for (int i = 0; i < mIvTypeIds.length; i++) {
                    mIvType[i] = helper.getView(mIvTypeIds[i]);
                }
                //小类
                for (int i = 0; i < mTvTypeSmallIds.length; i++) {
                    mTvTypeSmall[i] = helper.getView(mTvTypeSmallIds[i]);
                }
                for (int i = 0; i < mIvTypeSmallIds.length; i++) {
                    mIvTypeSmall[i] = helper.getView(mIvTypeSmallIds[i]);
                }
                if (HomeFragment.mGoodInfoType == 0) {
                    tvTypeColor(mTvType, mIvType, mTvType[0], mIvType[0], R.mipmap.icon_home_edinburgh_choose, mlLSmallTypeBg, R.color.homeEdinburghItem);
                    tvTypeSmallColor(mTvTypeSmall, mIvTypeSmall, mTvTypeSmall[0], R.color.homeEdinburgh, R.color.homeEdinburghChoose, mIvTypeSmall[0]);
                    rememberColor(R.mipmap.icon_home_edinburgh, "#c7693b", "#ea5d08");
                } else if (HomeFragment.mGoodInfoType == 1) {
                    tvTypeColor(mTvType, mIvType, mTvType[1], mIvType[1], R.mipmap.icon_home_will_choose, mlLSmallTypeBg, R.color.homeWillItem);
                    tvTypeSmallColor(mTvTypeSmall, mIvTypeSmall, mTvTypeSmall[0], R.color.homeWill, R.color.homeWillChoose, mIvTypeSmall[0]);
                    rememberColor(R.mipmap.icon_home_will, "#666666", "#333333");
                } else if (HomeFragment.mGoodInfoType == 2) {
                    tvTypeColor(mTvType, mIvType, mTvType[2], mIvType[2], R.mipmap.icon_home_fight_group_choose, mlLSmallTypeBg, R.color.homeFightGroupItem);
                    tvTypeSmallColor(mTvTypeSmall, mIvTypeSmall, mTvTypeSmall[0], R.color.homeFightGroup, R.color.homeFightGroupChoose, mIvTypeSmall[0]);
                    rememberColor(R.mipmap.icon_home_fight_group_circle, "#c8a200", "#aa8a00");
                } else if (HomeFragment.mGoodInfoType == 3) {
                    tvTypeColor(mTvType, mIvType, mTvType[3], mIvType[3], R.mipmap.icon_home_brand_choose, mlLSmallTypeBg, R.color.homeBrandItem);
                    tvTypeSmallColor(mTvTypeSmall, mIvTypeSmall, mTvTypeSmall[0], R.color.homeBrand, R.color.homeBrandChoose, mIvTypeSmall[0]);
                    rememberColor(R.mipmap.icon_home_brand, "#a764e6", "#8c54c1");
                }
                if (HomeFragment.mGoodInfoSmallType != 5) {
                    tvSmallColor(mTvTypeSmall, mIvTypeSmall, mTvTypeSmall[HomeFragment.mGoodInfoSmallType], mTypeColor, mTypeChooseColor, mIvTypeSmall[HomeFragment.mGoodInfoSmallType]);
                }
                //淘淘领
                helper.setOnClickListener(R.id.rl_type_edinburgh, v -> {
                    tvTypeColor(mTvType, mIvType, mTvType[0], mIvType[0], R.mipmap.icon_home_edinburgh_choose, mlLSmallTypeBg, R.color.homeEdinburghItem);
                    tvTypeSmallColor(mTvTypeSmall, mIvTypeSmall, mTvTypeSmall[0], R.color.homeEdinburgh, R.color.homeEdinburghChoose, mIvTypeSmall[0]);
                    rememberColor(R.mipmap.icon_home_edinburgh, "#c7693b", "#ea5d08");
                    if (homeAdapterOnClickListener != null) {
                        homeAdapterOnClickListener.bigTypeClick(0);
                    }
                });
                //会过
                helper.setOnClickListener(R.id.rl_type_will, v -> {
                    tvTypeColor(mTvType, mIvType, mTvType[1], mIvType[1], R.mipmap.icon_home_will_choose, mlLSmallTypeBg, R.color.homeWillItem);
                    tvTypeSmallColor(mTvTypeSmall, mIvTypeSmall, mTvTypeSmall[0], R.color.homeWill, R.color.homeWillChoose, mIvTypeSmall[0]);
                    rememberColor(R.mipmap.icon_home_will, "#666666", "#333333");
                    if (homeAdapterOnClickListener != null) {
                        homeAdapterOnClickListener.bigTypeClick(1);
                    }
                });
                //拼团领
                helper.setOnClickListener(R.id.rl_type_fight_group, v -> {
                    /* if (TextUtils.isEmpty(HomeFragment.mAreaCode)) {
                        TipUtils.showToast(App.getInstance(), "获取定位失败", 2);
                        return;
                    } */
                    tvTypeColor(mTvType, mIvType, mTvType[2], mIvType[2], R.mipmap.icon_home_fight_group_choose, mlLSmallTypeBg, R.color.homeFightGroupItem);
                    tvTypeSmallColor(mTvTypeSmall, mIvTypeSmall, mTvTypeSmall[0], R.color.homeFightGroup, R.color.homeFightGroupChoose, mIvTypeSmall[0]);
                    rememberColor(R.mipmap.icon_home_fight_group_circle, "#c8a200", "#aa8a00");
                    if (homeAdapterOnClickListener != null) {
                        homeAdapterOnClickListener.bigTypeClick(2);
                    }
                });
                //品牌领 更改为 9块9包邮
                helper.setOnClickListener(R.id.rl_type_brand, v -> {
                    /* if (TextUtils.isEmpty(HomeFragment.mAreaCode)) {
                        TipUtils.showToast(App.getInstance(), "获取定位失败", 2);
                        return;
                    } */
                    tvTypeColor(mTvType, mIvType, mTvType[3], mIvType[3], R.mipmap.icon_home_brand_choose, mlLSmallTypeBg, R.color.homeBrandItem);
                    tvTypeSmallColor(mTvTypeSmall, mIvTypeSmall, mTvTypeSmall[0], R.color.homeBrand, R.color.homeBrandChoose, mIvTypeSmall[0]);
                    rememberColor(R.mipmap.icon_home_brand, "#a764e6", "#8c54c1");
                    if (homeAdapterOnClickListener != null) {
                        homeAdapterOnClickListener.bigTypeClick(3);
                    }
                });
                //新品领
                /* helper.setOnClickListener(R.id.rl_type_new_product, v -> {
                    tvTypeColor(mTvType, mIvType, mTvType[3], mIvType[3], R.mipmap.icon_home_new_product_choose, mlLSmallTypeBg, R.color.homeNewProductItem);
                    tvTypeSmallColor(mTvTypeSmall, mIvTypeSmall, mTvTypeSmall[0], R.color.homeNewProduct, R.color.homeNewProductChoose, mIvTypeSmall[0]);
                    rememberColor(R.mipmap.icon_home_new_product, "#3da050", "#227d3f");
                    if (homeAdapterOnClickListener != null) {
                        homeAdapterOnClickListener.bigTypeClick(3);
                    }
                }); */
                //日用家居
                helper.setOnClickListener(R.id.rl_type_small_daily_home, v -> {
                    tvSmallColor(mTvTypeSmall, mIvTypeSmall, mTvTypeSmall[0], mTypeColor, mTypeChooseColor, mIvTypeSmall[0]);
                    if (homeAdapterOnClickListener != null) {
                        homeAdapterOnClickListener.smallTypeClick(0);
                    }
                });
                //数码家电
                helper.setOnClickListener(R.id.rl_type_small_electrical, v -> {
                    tvSmallColor(mTvTypeSmall, mIvTypeSmall, mTvTypeSmall[1], mTypeColor, mTypeChooseColor, mIvTypeSmall[1]);
                    if (homeAdapterOnClickListener != null) {
                        homeAdapterOnClickListener.smallTypeClick(1);
                    }
                });
                //母婴产品
                helper.setOnClickListener(R.id.rl_type_small_baby_product, v -> {
                    tvSmallColor(mTvTypeSmall, mIvTypeSmall, mTvTypeSmall[2], mTypeColor, mTypeChooseColor, mIvTypeSmall[2]);
                    if (homeAdapterOnClickListener != null) {
                        homeAdapterOnClickListener.smallTypeClick(2);
                    }
                });
                //服饰鞋包
                helper.setOnClickListener(R.id.rl_type_small_clothes, v -> {
                    tvSmallColor(mTvTypeSmall, mIvTypeSmall, mTvTypeSmall[3], mTypeColor, mTypeChooseColor, mIvTypeSmall[3]);
                    if (homeAdapterOnClickListener != null) {
                        homeAdapterOnClickListener.smallTypeClick(3);
                    }
                });
                //食品生鲜
                helper.setOnClickListener(R.id.rl_type_small_fresh_food, v -> {
                    tvSmallColor(mTvTypeSmall, mIvTypeSmall, mTvTypeSmall[4], mTypeColor, mTypeChooseColor, mIvTypeSmall[4]);
                    if (homeAdapterOnClickListener != null) {
                        homeAdapterOnClickListener.smallTypeClick(4);
                    }
                });
                break;

            case HomeMultiItemType.ITEM_GOOD_INFO:   //商品类型下面的商品信息
                RecyclerView rvGoodInfo = helper.getView(R.id.rv_home_good_info);
                NoScrollWebView wvHuiGuoWebView = helper.getView(R.id.wv_home_huiGuo_info);
                int goodInfoType2 = HomeFragment.mGoodInfoType;
                if (goodInfoType2 == 1) {
                    // 会过。
                    rvGoodInfo.setVisibility(View.GONE);
                    wvHuiGuoWebView.setVisibility(View.VISIBLE);
                    initHuiGuoWebView(wvHuiGuoWebView);
                    return;
                }
                rvGoodInfo.setVisibility(View.VISIBLE);
                wvHuiGuoWebView.setVisibility(View.GONE);

                // 设置布局管理器
                LinearLayoutManager linearManager = new LinearLayoutManager(context);
                // GoodInfoLinearLayoutManager linearManager = new GoodInfoLinearLayoutManager(context);
                rvGoodInfo.setLayoutManager(linearManager);
                rvGoodInfo.setFocusableInTouchMode(false); //设置不需要焦点
                rvGoodInfo.requestFocus(); //设置焦点不需要
                if (item == null) {
                    return;
                }

                int goodInfoType = item.mGoodInfoType;
                if (goodInfoType == 0 || goodInfoType == 1 || goodInfoType == 2 || goodInfoType == 3) {
                    if (eAdapter == null || rvGoodInfo.getAdapter() == null) {
                        fAdapter = null;
                        bAdapter = null;
                        eAdapter = new HomeEdinburghGoodsAdapter(context, item.homeGoodInfo);
                        rvGoodInfo.setHasFixedSize(true);
                        rvGoodInfo.setAdapter(eAdapter);
                    } else {
                        eAdapter.setNewData(item.homeGoodInfo);
                    }
                    if (eAdapter.getItemCount() < 4) {
                        rvGoodInfo.setNestedScrollingEnabled(false);
                    }

                    if (eAdapter != null) {
                        eAdapter.setOnItemClickListener(new OnItemClickListener() {
                            @Override
                            public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
                                if (homeAdapterOnClickListener != null) {
                                    if (item.homeGoodInfo != null) {
                                        //商品点击
                                        //item.homeGoodInfo.get(position).getPic_info_url());
                                        homeAdapterOnClickListener.edinburghClick(
                                                item.homeGoodInfo.get(position).getGoods_id(),
                                                item.homeGoodInfo.get(position).getData_source(),
                                                item.homeGoodInfo.get(position).getPic_info_url());
                                    }
                                }
                            }
                        });
                    }

                } else if (item.mGoodInfoType == 9999) {
                    if (fAdapter == null) {
                        eAdapter = null;
                        bAdapter = null;
                        fAdapter = new HomeFightGroupAdapter(context, item.homeGoodInfo, item.mUrlMap);
                        rvGoodInfo.setAdapter(fAdapter);
                        fAdapter.setOnItemClickListener(new OnItemClickListener() {
                            @Override
                            public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
                                if (homeAdapterOnClickListener != null) {
                                    homeAdapterOnClickListener.fightGroupClick(
                                            item.homeGoodInfo.get(position).getGoods_id(),
                                            item.homeGoodInfo.get(position).getPic_info_url());
                                }
                            }
                        });
                    } else {
                        fAdapter.notifyDataSetChanged();
                    }
                }
                /* else if (item.mGoodInfoType == 3) {
                    if (bAdapter == null) {
                        fAdapter = null;
                        eAdapter = null;
                        bAdapter = new HomeBrandAdapter(context, item.homeGoodInfo);
                        rvGoodInfo.setAdapter(bAdapter);
                        bAdapter.setOnItemClickListener(new OnItemClickListener() {
                            @Override
                            public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
                                if (homeAdapterOnClickListener != null) {
                                    homeAdapterOnClickListener.brandClick(item.homeGoodInfo.get(position).getBrandName());
                                }
                            }
                        });
                    }else{
                        bAdapter.notifyDataSetChanged();
                    }
                } */
                break;
            case HomeMultiItemType.ITEM_PULL_DATA:   //加载更多的布局
                mProgressBar = helper.getView(R.id.pb_load);
                mTvText = helper.getView(R.id.tv_load);
                mLlNoData = helper.getView(R.id.ll_no_data);
                mIvNoData = helper.getView(R.id.iv_no_data);
                mTvNoData = helper.getView(R.id.tv_no_data);
                //0代表不没有更多了 1代表可以加载更改 2代表没有数据 3代表不没有更多了下面留白 5加载中 下面留白  6没找到网络
                if (mLoadMoreType == 0) {
                    mProgressBar.setVisibility(View.GONE);
                    mTvText.setText("没有更多了");
                    mLlNoData.setVisibility(View.GONE);
                } else if (mLoadMoreType == 1) {
                    mProgressBar.setVisibility(View.VISIBLE);
                    mTvText.setText("加载中");
                    mLlNoData.setVisibility(View.GONE);
                } else if (mLoadMoreType == 2) {
                    mProgressBar.setVisibility(View.GONE);
                    mTvText.setText("");
                    mLlNoData.setVisibility(View.VISIBLE);
                    mIvNoData.setVisibility(View.VISIBLE);
                    mIvNoData.setBackgroundResource(R.mipmap.icon_no_network);
                    mTvNoData.setText("没找到商品");
                } else if (mLoadMoreType == 3) {
                    mProgressBar.setVisibility(View.GONE);
                    mTvNoData.setText("");
                    mTvText.setText("");
                    mIvNoData.setVisibility(View.GONE);
                    mLlNoData.setVisibility(View.VISIBLE);
                } else if (mLoadMoreType == 5) {
                    mProgressBar.setVisibility(View.VISIBLE);
                    mTvText.setText("加载中");
                    mLlNoData.setVisibility(View.GONE);
                } else if (mLoadMoreType == 6) {
                    mProgressBar.setVisibility(View.GONE);
                    mTvText.setText("");
                    mLlNoData.setVisibility(View.VISIBLE);
                    mIvNoData.setVisibility(View.VISIBLE);
                    mIvNoData.setBackgroundResource(R.mipmap.icon_no_network);
                    mTvNoData.setText("没找到网络");
                }
                break;
        }
    }

    /*
     * 初始化“会过” WebView.
     */
    private void initHuiGuoWebView(NoScrollWebView webView) {
        WebSettings webSettings = webView.getSettings();
        webSettings.setJavaScriptEnabled(true);
        webSettings.setDefaultTextEncodingName("utf-8");
        webSettings.setSupportZoom(true);
        webSettings.setBuiltInZoomControls(false);
        webSettings.setUseWideViewPort(true);
        webSettings.setLoadWithOverviewMode(true);
        webSettings.setCacheMode(WebSettings.LOAD_DEFAULT);
        //webSettings.setDomStorageEnabled(true);
        webView.setWebViewClient(new WebViewClient() {
            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url) {
                view.loadUrl(url);
                return true;
            }
        });
        webView.setWebChromeClient(new WebChromeClient());

        String url = Constants.HOST + "h5/share";
        webView.loadUrl(url);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            webView.setWebContentsDebuggingEnabled(true);
        }
        // H5的 JS 回调。
        webView.addJavascriptInterface(new HuiGuoWebPageHelper(context), "jsObj");

    }

    public class GlideImageLoader extends ImageLoader {
        @Override
        public void displayImage(Context context, Object path, ImageView imageView) {
            GlideUtils.setRectImage(mContext, (String) path, R.mipmap.icon_default_picture, R.mipmap.icon_default_picture, imageView);
        }
    }

    private ProgressBar mProgressBar;
    private TextView mTvText;
    private LinearLayout mLlNoData;
    private ImageView mIvNoData;
    private TextView mTvNoData;

    /**
     * 是否可以加载更多
     *
     * @param loadMore
     */
    public void setCanLoadMore(boolean loadMore) {
        if (!loadMore) {
            mLoadMoreType = 0;
            try {
                mProgressBar.setVisibility(View.GONE);
                mTvText.setText("没有更多了");
                mLlNoData.setVisibility(View.GONE);
            } catch (Exception e) {
                e.printStackTrace();
            }
        } else {
            try {
                mLoadMoreType = 1;
                mProgressBar.setVisibility(View.VISIBLE);
                mLlNoData.setVisibility(View.GONE);
                mTvText.setText("加载中");
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }

    //加载更多失败  显示没有找到商品
    public void setFailLoadMore() {
        mLoadMoreType = 2;
    }

    //没有更多了 留白
    public void setNoMore() {
        mLoadMoreType = 3;
    }

    //加载中 下面留白 防止跳转严重
    public void setCanLoadMore() {
        try {
            mLoadMoreType = 5;
            mProgressBar.setVisibility(View.VISIBLE);
            mTvText.setText("加载中");
            mLlNoData.setVisibility(View.GONE);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    //没有网络
    public void setNoNetWork(boolean isset) {
        mLoadMoreType = 6;
        if (isset) {
            try {
                mProgressBar.setVisibility(View.GONE);
                mTvText.setText("");
                mLlNoData.setVisibility(View.VISIBLE);
                mIvNoData.setBackgroundResource(R.mipmap.icon_no_network);
                mTvNoData.setText("没找到网络");
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }

    /**
     * 点击大类颜色背景的改变
     *
     * @param tv   大类目文本
     * @param iv   类目下面图片是否选中
     * @param bg   文本的背景
     * @param ll   小类目LinearLayout
     * @param llBg 小类目LinearLayout背景
     */
    private void tvTypeColor(TextView tvType[], ImageView ivType[], TextView tv, ImageView iv, int bg, LinearLayout ll, int llBg) {
        for (int i = 0; i < tvType.length; i++) {
            tvType[i].setBackgroundResource(R.color.transparent);
            tvType[i].setTextColor(context.getResources().getColor(R.color.text_color_normal));
            ivType[i].setVisibility(View.INVISIBLE);
        }
        tv.setBackgroundResource(bg);
        tv.setTextColor(context.getResources().getColor(R.color.white));
        iv.setVisibility(View.VISIBLE);
        ll.setBackgroundResource(llBg);
        ll.setVisibility(View.VISIBLE);
    }

    /**
     * 点击大类记住颜色
     */
    private void rememberColor(int bg, String color, String chooseColor) {
        mTypeChooseBg = bg;
        mTypeColor = color;
        mTypeChooseColor = chooseColor;
    }

    /**
     * 点击大类改变小类颜色
     */
    private void tvTypeSmallColor(TextView tvType[], ImageView ivType[], TextView tv, int color, int chooseColor, ImageView iv) {
        for (int i = 0; i < tvType.length; i++) {
            tvType[i].setTextColor(context.getResources().getColor(color));
        }
        for (int i = 0; i < ivType.length; i++) {
            ivType[i].setBackgroundResource(R.color.transparent);
        }
//        tv.setTextColor(context.getResources().getColor(chooseColor));
//        iv.setBackgroundResource(mTypeChooseBg);
    }

    /**
     * 点击小类改变小类颜色
     */
    private void tvSmallColor(TextView tvType[], ImageView ivType[], TextView tv, String normalColor, String chooseColor, ImageView iv) {
        for (int i = 0; i < ivType.length; i++) {
            ivType[i].setBackgroundResource(R.color.transparent);
            tvType[i].setTextColor(Color.parseColor(normalColor));
        }
        iv.setBackgroundResource(mTypeChooseBg);
        tv.setTextColor(Color.parseColor(chooseColor));
    }

    private HomeAdapterOnClickListener homeAdapterOnClickListener;

    public void setOnHomeAdapterOnClickListener(HomeAdapterOnClickListener homeAdapterOnClickListener) {
        this.homeAdapterOnClickListener = homeAdapterOnClickListener;
    }

    public interface HomeAdapterOnClickListener {
        //搜索
        void searchClick();

        //扫描二维码
        void scanCodeClick();

        //签到
        void signInClick();

        //话费充值
        void phoneChargeClick();

        //新人攻略
        void newStrategyClick();

        //会员权益
        void memberRulesClick();

        //合作商家
        void businessCooClick();

        //大类型版块选项
        void bigTypeClick(int position);

        //小类型版块选项
        void smallTypeClick(int position);

        //限时抢购
        void limitTimeClick(String goodId, String pathPic);

        //明日预告
        void tomorrowClick(String goodId);

        // 0元购 点击。
        void zeroBuyClick();

        //淘淘领 和 会过的点击
        void edinburghClick(String goodId, String data_source, String pic_info_url);

        //拼团领
        void fightGroupClick(String goodId, String pic_info_url);

        //品牌领
        void brandClick(String goodId);
    }

}
